/*
 * @Author:
 * @Date: 2022-06-19 00:03:50
 * @LastEditTime: 2022-06-19 20:33:41

 */
import {Component, OnInit} from '@angular/core';
import {ApiPath} from '../../config/api-path';
import {HttpService} from '../../service/http.service';
import {AlertController} from '@ionic/angular';
import {PostCreate} from '../../model/post-create';
import {Router} from '@angular/router';
import {Location} from '@angular/common';

@Component({
  selector: 'app-help-form',
  templateUrl: './help-form.component.html',
  styleUrls: ['./help-form.component.scss'],
})
export class HelpFormComponent implements OnInit {
  // files = [];
  // multiple = false;
  // multipleTab = 0;
  constructor(
    private HttpSrv: HttpService,
    private router: Router,
    private alertCtrl: AlertController,
    private location:  Location

  ) { }

  post: PostCreate ={
    title: '',
    postType: 'h',
    keyWord: '',
    campus: '',
    foodDescription: '',
    outAddress: '',
    inAddress: '',
    content: '',
    pictureUrl: '',
    appointedTime: '',
  };

  ngOnInit() {}

  /**
   * 发送按钮绑定该函数。
   */
  sendPost() {
    console.debug('post: ', this.post);
    if(this.post.title==''){
      this.showAlert('请输入标题！').then(r => r);
      return;
    }
    this.HttpSrv.httpPost<any>(ApiPath.request.forum.newPost, this.post).subscribe(res => {
      if (res.code == 0) {
        this.showAlert('发送成功！').then(r => r);
      }else
      {this.showAlert(res.msg).then(r => r);}
    });
    this.router.navigate(['ynuer/ask']).then(r => r);
  }

  initi() {

  }

  async showAlert(msg: string) {
    const alert = await this.alertCtrl.create({
      message: msg,
      buttons: ['确定']
    });
    await alert.present();
  }
  fileChange(event) {}
  imageClick(event) {}
  onLeftClick() {
    this.location.back();
  }
}

